package com.android.monee.view.model;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import android.content.res.Resources;
import android.graphics.Color;

import com.android.monee.data.model.Budget;
import com.android.monee.data.model.Mensuality;
import com.android.monee.domain.BudgetService;
import com.android.monee.R;

public class MensualityHistoFollow extends Mensuality {

	private Resources res;
	private String currency;
	private String mensAbb;
	private BudgetService budget;
	
	public MensualityHistoFollow(Budget budget, Resources res) {
		super(budget);
		constructor(res);
	}

	public MensualityHistoFollow(Mensuality mensuality, Resources res) {
		super(mensuality);
		constructor(res);
	}

	private void constructor(Resources res){
		this.res = res;
		this.currency = res.getText(R.string.currency).toString();
		this.mensAbb = res.getText(R.string.mens_abb).toString();
		this.budget = BudgetService.findById(super.getBudgetId());
	}

	public String getMainLib() {
		return this.mensAbb + " " + super.getNumber() + "/"
				+ this.budget.getTotalNbMens() + " - " + this.budget.getName();
	}

	public String getAmountLib() {
		DecimalFormat format = new DecimalFormat("#.#"+this.currency);
		return format.format(super.getAmount());
	}
	
	public int getbBackgroundColor(){
		if(isDone()){
			return Color.parseColor("#55545a");
		}
		else
			return Color.parseColor("#ebebeb");
	}
	
	public int getTextColor(){
		if(isDone()){
			return Color.LTGRAY;
		}
		else
			return Color.BLACK;
	}

	public static List<MensualityHistoFollow> newCollection(Collection<? extends Mensuality> mensualities, Resources res){
		List<MensualityHistoFollow> newCol = new ArrayList<MensualityHistoFollow>();
		for(Mensuality mens : mensualities){
			newCol.add(new MensualityHistoFollow(mens, res));
		}
		return newCol;
	}
}
